package com.yida.gwj.config.controller;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson2.JSONObject;
import com.yida.common.core.domain.R;
import com.yida.common.core.utils.poi.ExcelUtil;
import com.yida.common.core.web.controller.BaseController;
import com.yida.common.core.web.domain.AjaxResult;
import com.yida.common.core.web.page.TableDataInfo;
import com.yida.common.log.annotation.Log;
import com.yida.common.log.enums.BusinessType;
import com.yida.common.security.annotation.InnerAuth;
import com.yida.common.security.annotation.RequiresPermissions;
import com.yida.gwj.api.domain.GwjConfBusinessFlag;
import com.yida.gwj.config.service.IGwjConfBusinessFlagService;

/**
 * 业务标识Controller
 * <p>
 * 修订20230112 hmh(修改地址，权限标注，方法名替换)
 *
 * @author lqq
 * @date 2022-12-21
 */
@RestController
@RequestMapping("/bizFlag")
public class GwjConfBusinessFlagController extends BaseController {
    @Autowired
    private IGwjConfBusinessFlagService gcBusinessFlagService;

    /**
     * 查询业务标识列表
     */
    @GetMapping("/list")
    @RequiresPermissions("gwj:config:bizFlag:list")
    public TableDataInfo list(GwjConfBusinessFlag gcBusinessFlag) {
        startPage();
        List<GwjConfBusinessFlag> list = gcBusinessFlagService.selectGwjConfBusinessFlagList(gcBusinessFlag);
        return getDataTable(list);
    }

    /**
     * 导出业务标识列表
     */
    @PostMapping("/export")
    @RequiresPermissions("gwj:config:bizFlag:export")
    @Log(title = "业务标识", businessType = BusinessType.EXPORT, systemName = "gwj")
    public void export(HttpServletResponse response, GwjConfBusinessFlag gcBusinessFlag) {
        List<GwjConfBusinessFlag> list = gcBusinessFlagService.selectGwjConfBusinessFlagList(gcBusinessFlag);
        ExcelUtil<GwjConfBusinessFlag> util = new ExcelUtil<>(GwjConfBusinessFlag.class);
        util.exportExcel(response, list, "业务标识数据");
    }

    /**
     * 获取业务标识详细信息
     */
    @GetMapping(value = "/{bizFlagId}")
    @RequiresPermissions("gwj:config:bizFlag:query")
    public AjaxResult getInfo(@PathVariable("bizFlagId") Integer bizFlagId) {
        return AjaxResult.success(gcBusinessFlagService.selectGwjConfBusinessFlagByBizFlagId(bizFlagId));
    }

    /**
     * 新增业务标识
     */
    @PostMapping
    @RequiresPermissions("gwj:config:bizFlag:add")
    @Log(title = "业务标识", businessType = BusinessType.INSERT, systemName = "gwj")
    public AjaxResult add(@RequestBody GwjConfBusinessFlag commonBusinessFlag) {
        return toAjax(gcBusinessFlagService.insertGwjConfBusinessFlag(commonBusinessFlag));
    }

    /**
     * 修改业务标识
     */
    @PutMapping
    @RequiresPermissions("gwj:config:bizFlag:edit")
    @Log(title = "业务标识", businessType = BusinessType.UPDATE, systemName = "gwj")
    public AjaxResult edit(@RequestBody GwjConfBusinessFlag commonBusinessFlag) {
        return toAjax(gcBusinessFlagService.updateGwjConfBusinessFlag(commonBusinessFlag));
    }

    /**
     * 删除业务标识
     */
    @DeleteMapping("/{bizFlagIds}")
    @RequiresPermissions("gwj:config:bizFlag:remove")
    @Log(title = "业务标识", businessType = BusinessType.DELETE, systemName = "gwj")
    public AjaxResult remove(@PathVariable Long[] bizFlagIds) {
        return toAjax(gcBusinessFlagService.deleteGwjConfBusinessFlagByBizFlagIds(bizFlagIds));
    }

    /**
     * 根据业务标识ID查询业务步骤配置信息
     */
    @InnerAuth
    @GetMapping("/inner/{bizFlagId}")
    public R<GwjConfBusinessFlag> selectGwjConfBusinessFlagByBizFlagId(@PathVariable("bizFlagId") Integer bizFlagId) {
        return R.ok(gcBusinessFlagService.selectGwjConfBusinessFlagByBizFlagId(bizFlagId));
    }

    /**
     * 根据业务标识ID查询业务步骤配置信息
     */
    @InnerAuth
    @PostMapping("/inner/selectConfBusinessFlagList")
    public R<List<GwjConfBusinessFlag>> selectConfBusinessFlagList(GwjConfBusinessFlag confBusinessFlag) {
        return R.ok(gcBusinessFlagService.selectGwjConfBusinessFlagList(confBusinessFlag));
    }

    /**
     * 根据业务标识ID查询完整业务步骤配置信息
     */
    @InnerAuth
    @GetMapping("/inner/flag/{bizFlagId}")
    public R<JSONObject> selectGwjConfBusinessFlagInfoByBizFlagId(@PathVariable("bizFlagId") Integer bizFlagId) {
        return R.ok(gcBusinessFlagService.selectGwjConfBusinessFlagInfoByBizFlagId(bizFlagId));
    }
}
